<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>智慧社区后台-社区圈</title>
<meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/css/AdminLTE.min.css">
<link rel="stylesheet" type="text/css" href="${pageContext.request.contextPath}/plugins/bootstrap-table/css/bootstrap-table.css">
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/lightbox2/css/lightbox.min.css">
<!-- 文件上传css -->
<link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap_fileupload/css/fileinput.min.css">
</head>
<body style="padding-bottom: 90px; background-color: #ECF0F5;">
	<section class="content" style="margin: 15px; background-color: white;">
		<div class="row">
			<div class="col-sm-12">
				<table id="table">
					<thead style="background-color: #00C0EF">
						<tr style="background-color: #00C0EF">
							<th class="text-center" data-field="userName">发布人姓名</th>
							<th class="text-center" data-field="createTime">发布时间</th>
							<th class="text-center" data-field="content">内容</th>
							<th class="text-center" data-field="id">操作</th>
						</tr>
					</thead>
				</table>
			</div>
		</div>
	</section>
	<!-- Large modal -->
	<div id="modal" class="modal fade bs-example-modal-lg" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">社区圈添加</h4>
				</div>
				<div class="modal-body">
					<div class="form-group" id="tp"></div>
					<div class="form-group">
						<label for="content" class="control-label">内容：</label>
						<textarea id="content" style="width: 100%; height: 100px; resize: none;"></textarea>
					</div>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
					<button id="circleBtn" type="button" class="btn btn-primary" onclick="addCircle();">提交</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Large modal -->
	<div id="graceModal" class="modal fade" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">社区圈详情</h4>
				</div>
				<div class="modal-body">
					<ul class="media-list" id="graceList">

					</ul>
					<ul id="reply">

					</ul>
					<hr />
					<div class="form-group">
						<textarea id="replyContent" style="width: 100%; height: 100px; resize: none"></textarea>
					</div>
				</div>
				<div class="modal-footer">
					<button id="replyButton" type="button" class="btn btn-primary" onclick="submitReply();">发表回复</button>
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
	<!-- Large modal -->
	<div id="complaintModal" class="modal fade bs-example-modal-lg" role="dialog" aria-labelledby="myLargeModalLabel">
		<div class="modal-dialog modal-lg" role="document">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal" aria-label="Close">
						<span aria-hidden="true">&times;</span>
					</button>
					<h4 class="modal-title">投诉列表</h4>
				</div>
				<div class="modal-body">
					<table class="table table-bordered table-condensed">
						<thead>
							<tr>
								<th>投诉人</th>
								<th>投诉内容</th>
								<th>投诉人电话</th>
							</tr>
						</thead>
						<tbody id="complaint">
						</tbody>
					</table>
				</div>
				<div class="modal-footer">
					<button type="button" class="btn btn-default" data-dismiss="modal">关闭</button>
				</div>
			</div>
		</div>
	</div>
</body>
<script src="${pageContext.request.contextPath}/plugins/lightbox2/js/lightbox-plus-jquery.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-zh-CN.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-export.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/tableExport.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-toolbar.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-table/js/bootstrap-table-filter-control.js"></script>
<!-- layer -->
<script src="${pageContext.request.contextPath}/plugins/layer/2.4/layer.js"></script>
<script src="${pageContext.request.contextPath}/plugins/laydate/laydate.js"></script>
<script src="${pageContext.request.contextPath}/js/date.js"></script>
<!-- 文件上传js -->
<script src="${pageContext.request.contextPath}/plugins/bootstrap_fileupload/js/fileinput.min.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap_fileupload/js/locales/zh.js" type="text/javascript"></script>
<script src="${pageContext.request.contextPath}/js/ajaxfileupload.js"></script>
<script>
	var selectId = "";
	function actionFormatter(value, row, index) {
		return [ "<button class='btn btn-warning btn-xs glyphicon glyphicon-list' onclick='showModal1(\"" + row.id + "\");'>投诉列表</button>",
				"&nbsp;<button class='btn btn-success btn-xs glyphicon glyphicon-file' onclick='showModal(\"" + row.id + "\");'>查看详情</button>",
				"&nbsp;<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' onclick='delCircle(\"" + row.id + "\")'>删除信息</button>", ].join('');
	}
	var table_dataset = [ {
		field : 'userName',
		align : 'center',
	}, {
		field : 'createTime',
		align : 'center',
		formatter : function timeFormatter(value, row, index) {
			return (new Date(row.createTime)).Format("yyyy-MM-dd hh:mm:ss");
		}
	}, {
		field : 'content',
		align : 'center',
	}, {
		align : 'center',
		width : 300,
		formatter : actionFormatter,
	} ];
	$('#table').bootstrapTable({
		url : "${pageContext.request.contextPath}/selectCommunityCirclePager",
		idField : "vmId",
		columns : table_dataset,
		striped : true, //是否显示行间隔色
		pagination : true, //是否显示分页
		pageSize : 10, //每页的记录行数
		pageList : [ 10, 25, 50, 100 ], //可供选择的每页的行数
		search : false, //是否显示搜索
		showRefresh : true,
		sidePagination : "server", //表示服务端请求  
		queryParamsType : "limit",
		queryParams : function queryParams(params) { //设置查询参数  
			var param = {
				offset : params.offset,
				limit : params.limit
			};
			return param;
		},
		toolbar : "<button class='btn btn-primary glyphicon glyphicon-plus' onclick='showCircleModal(\"" + '' + "\");'>新增数据</button>",
		// 						+"&nbsp;<button class='btn btn-danger glyphicon glyphicon-trash'>批量删除</button>",
		icons : {
			paginationSwitchDown : 'glyphicon-collapse-down icon-chevron-down',
			paginationSwitchUp : 'glyphicon-collapse-up icon-chevron-up',
			refresh : 'glyphicon-refresh icon-refresh',
			toggle : 'glyphicon-list-alt icon-list-alt',
			columns : 'glyphicon-th icon-th',
			detailOpen : 'glyphicon-plus icon-plus',
			detailClose : 'glyphicon-minus icon-minus',
			"export" : 'glyphicon-export icon-share'
		},
		showExport : true,
		exportDataType : 'basic',
		exportTypes : [ 'json', 'xml', 'csv', 'txt', 'sql', 'excel' ]
	});

	function showModal(id) {
		$("#replyContent").val('');
		selectId = id;
		$
				.ajax({
					url : "${pageContext.request.contextPath}/selectCommunityCircleById",
					type : "post",
					data : {
						id : selectId
					},
					dataType : "json",
					success : function(map) {
						var circle = map['circle'];
						var list = map['list'];
						var path = "";
						var replys = "";
						var picture = circle.picture;
						if (picture != null & picture != '') {
							var pictures = picture.split("★");
							if (pictures.length != 0) {
								for (var j = 0; j < pictures.length; j++) {
									path += "<a href='../upload/zhsq_xg/"+pictures[j]+"' class='example-image-link' data-lightbox='example-"+circle.id+"'>"
											+ "<img class='example-image' style='width:40px;height:40px;' src='../upload/zhsq_xg/"+pictures[j]+"'></a>&nbsp;";
								}
							}
						}
						var urlStr = "img/mine_user.png";
						if (circle.userPicture != null & circle.userPicture != '') {
							urlStr = circle.userPicture;
						}
						var str = "<li class='media'>" + "<div class='media-left'>" + "<a href='#'>" + "<img style='width:64px;height:64px;border-radius: 0%;' class='media-object img-circle' src='"
								+ urlStr + "'>" + "</a>" + "</div>" + "<div class='media-body'>" + "<h4 class='media-heading'>" + circle.userName + "</h4>" + "<p>" + circle.content + "</p>" + path
								+ "<div class='ds-comment-footer'>" + "<span class='ds-time'>" + (new Date(circle.createTime)).Format("yyyy-MM-dd hh:mm:ss") + "</span>&nbsp;" + "</div>"
								+ "</div></li><hr />";
						$("#graceList").html(str);
						if (list.length != 0) {
							for (var i = 0; i < list.length; i++) {
								var name = list[i].replyName;
								var object = list[i].replyObject;
								var content = list[i].replyContent;
								var str = name;
								if (object != '') {
									str += "&nbsp;回复&nbsp;" + object + "：";
								} else {
									str += "：";
								}
								str += content;
								replys += "<li id='"+list[i].id+"' style='list-style-type: none;'>" + str
										+ "<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' style='float: right;line-height: 1.2;' onclick='delReply(\"" + list[i].id
										+ "\")'>删除</button></li>";
							}
						}
						$("#reply").html(replys);
						$('#graceModal').modal({
							backdrop : 'static',
							keyboard : false
						});
					}
				});
	}

	function showModal1(id) {
		$.ajax({
			url : "${pageContext.request.contextPath}/selectCommunityComplaint",
			type : "post",
			data : {
				id : id
			},
			dataType : "json",
			success : function(map) {
				var list = map['list'];
				var trs = "";
				if (list.length != 0) {
					for (var i = 0; i < list.length; i++) {
						trs += "<tr><td>" + list[i].userName + "</td><td>" + list[i].text + "</td><td>" + list[i].userMobile + "</td></tr>";
					}
				}
				$("#complaint").html(trs);
				$('#complaintModal').modal({
					backdrop : 'static',
					keyboard : false
				});
			}
		});
	}

	function showCircleModal() {
		$("#tp").html(
				'<label for="xstp">显示图片：<input id="xstp" name="xstp" type="file" multiple class="file-loading form-control" data-overwrite-initial="false" style="height: 40px;" placeholder="图片显示">');
		/*初始化文件上传*/
		$("#xstp").fileinput({
			language : 'zh',
			maxFileCount : 9,
			uploadUrl : '#', // you must set a valid URL here else you will get an error
			allowedFileExtensions : [ 'jpg', 'jpeg', 'png', 'gif' ],
			overwriteInitial : false,
			maxFileSize : 5120,
			maxFilesNum : 10,
			slugCallback : function(filename) {
				return filename.replace('(', '_').replace(']', '_');
			},
			showRemove : true,
			showUpload : false,
			allowedFileExtensions : [ 'jpg', 'jpeg', 'png', 'gif' ],
			fileActionSettings : {
				showUpload : false,
				showZoom : false,
				indicatorNew : '',
				indicatorSuccess : '',
				indicatorError : '',
				indicatorLoading : '',
				indicatorNewTitle : '',
				indicatorSuccessTitle : '',
				indicatorErrorTitle : '',
				indicatorLoadingTitle : '',
			}
		});
		$("#content").val('');
		$('#modal').modal({
			backdrop : 'static',
			keyboard : false
		});
	}

	function addCircle() {
		$("#circleBtn").button('loading');
		var content = $("#content").val();
		if (content == '') {
			layer.alert("请填写内容!");
			$("#circleBtn").button('reset');
			return;
		}
		$.ajaxFileUpload({
			url : '${pageContext.request.contextPath}/insertCommunityCircle',
			secureuri : false,
			fileElementId : [ 'xstp' ],
			dataType : 'multipart/form-data',
			data : {
				content : content
			},
			async : false,
			success : function(map) {
				console.log(map);
				var mapResult = map.match("\{.{1,100}\}");
				var json = JSON.parse(mapResult);
				if (json['result'] == "1") {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						$("#table").bootstrapTable('refresh');
						$("#modal").modal("hide");
					}, 500);
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
				$("#circleBtn").button('reset');
			}
		});
	}

	function delCircle(id) {
		layer.confirm("是否要删除此社区圈？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/delCommunityCircle",
				type : "post",
				data : {
					id : id
				},
				dataType : "json",
				success : function(data) {
					if (data.result == "1") {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							$("#table").bootstrapTable('refresh');
						}, 500);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function delReply(id) {
		layer.confirm("是否要删除此回复？", function(index) {
			$.ajax({
				url : "${pageContext.request.contextPath}/delCommunityReply",
				type : "post",
				data : {
					id : id
				},
				dataType : "json",
				success : function(data) {
					if (data.result == "1") {
						layer.msg('操作成功!', {
							icon : 1,
							time : 800
						});
						setTimeout(function() {
							$("#" + id).remove();
						}, 500);
					} else {
						layer.msg('操作失败!', {
							icon : 2,
							time : 800
						});
					}
				},
				error : function() {
					layer.msg('系统繁忙，请稍后再试!', {
						icon : 5,
						time : 800
					});
				}
			});
		});
	}

	function submitReply() {
		$("#replyButton").button('loading');
		var replyContent = $("#replyContent").val();
		if (replyContent == '') {
			layer.alert("请填写回复!");
			$("#replyButton").button('reset');
			return;
		}
		$.ajax({
			url : "${pageContext.request.contextPath}/insertCommunityReply",
			type : "post",
			data : {
				id : selectId,
				replyContent : replyContent
			},
			dataType : "json",
			success : function(data) {
				var result = data['result'];
				if (result === 1) {
					layer.msg('操作成功!', {
						icon : 1,
						time : 800
					});
					setTimeout(function() {
						var reply = "<li id='"+data.replyId+"' style='list-style-type: none;'>" + data.name + "：" + replyContent
								+ "<button class='btn btn-danger btn-xs glyphicon glyphicon-trash' style='float: right;line-height: 1.2;' onclick='delReply(\"" + data.replyId
								+ "\")'>删除</button></li>";
						$("#reply").append(reply);
						$("#replyContent").val('');
					}, 1000);
					$("#modal").modal("hide");
				} else {
					layer.msg('操作失败!', {
						icon : 2,
						time : 800
					});
				}
				$("#replyButton").button('reset');
			}
		})
	}
</script>
</html>
